package org.dromara.oce.domain.req;

import com.bytedance.ads.model.NativeAnchorCreateV30AnchorInfoAnchorType;
import com.bytedance.ads.model.NativeAnchorCreateV30RequestAnchorInfoNetServiceAnchorAppImagesInner;
import com.bytedance.ads.model.NativeAnchorCreateV30RequestAnchorInfoNetServiceAnchorHeadImageListInner;
import com.bytedance.ads.model.NativeAnchorCreateV30RequestAnchorInfoNetServiceAnchorIconImagesInner;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.ObjectUtils;
import org.dromara.oce.domain.base.OceBaseReq;

/**
 * @desc: https://open.oceanengine.com/labels/34/docs/1757798123491403?origin=left_nav
 * @author: cx
 * @date：2025/6/5 10:11
 */
@Data
public class CreateNativeAnchorV3Request extends OceBaseReq {

    /**
     * 业务数据。
     */
    @NotNull(message = "锚点信息必传")
    private CreateNativeAnchorV3RequestAnchor anchorInfo ;


    /**
     * 图片id截取
     */
    public void urlFilter(){
        if(NativeAnchorCreateV30AnchorInfoAnchorType.APP_INTERNET_SERVICE.equals(this.anchorInfo.getAnchorType())){
            if(ObjectUtils.isEmpty(this.anchorInfo.getNetServiceAnchor())){
                throw new ServiceException("网服下载锚点信息不全");
            }
            for (NativeAnchorCreateV30RequestAnchorInfoNetServiceAnchorAppImagesInner appImage : this.anchorInfo.getNetServiceAnchor().getAppImages()) {
                if(ObjectUtils.isEmpty(appImage.getUri())){
                    throw new ServiceException("app图片地址不能为空");
                }
                appImage.setUri(appImage.getUri().substring(appImage.getUri().indexOf("tos-cn"),appImage.getUri().indexOf("~tplv-")));
            }

            for (NativeAnchorCreateV30RequestAnchorInfoNetServiceAnchorHeadImageListInner image : this.anchorInfo.getNetServiceAnchor().getHeadImageList()) {
                if(ObjectUtils.isEmpty(image.getUri())){
                    throw new ServiceException("锚点头部图片地址不能为空");
                }
                image.setUri(image.getUri().substring(image.getUri().indexOf("tos-cn"),image.getUri().indexOf("~tplv-")));
            }

            for (NativeAnchorCreateV30RequestAnchorInfoNetServiceAnchorIconImagesInner image : this.anchorInfo.getNetServiceAnchor().getIconImages()) {
                if(ObjectUtils.isEmpty(image.getUri())){
                    throw new ServiceException("应用icon图片地址不能为空");
                }
                image.setUri(image.getUri().substring(image.getUri().indexOf("tos-cn"),image.getUri().indexOf("~tplv-")));
            }

        }


    }
}
